<?
include("/var/www/html/new/com.inc.php");
include("/var/www/html/new/d/class/ProductInfo.php");
include("/var/www/html/new/d/class/OrderRecord.php");
include("/var/www/html/new/d/class/OrderRecord_c_dev.php");
// include("/var/www/html/new/conf/yd.le.je");
// include_once("/var/www/html/new/d/common/yd.le.je");//连接云顶的数据库
// $ydle=new yd_go_sql();
// $ydle->connect(); 
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];

$script_uri = substr($_SERVER['SCRIPT_URI'],0,strrpos($_SERVER['SCRIPT_URI'],'/'));
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$ordernum=$_REQUEST['ordernum'];

if(substr($ordernum,0,2)=='st'){ // 是否合并的订单
	exit;
    $sql="SELECT old FROM uu_unitpay WHERE new='$ordernum' AND status=0 LIMIT 1";
    $GLOBALS['le']->query($sql);
    $GLOBALS['le']->fetch_assoc();
    $subOrders = $GLOBALS['le']->f('old');
    $subOrders = explode(',', $subOrders);
    $totalMenoey = 0;
    $mid = 0;
    foreach($subOrders as $v){
        $or=new OrderRecord_c($v,$s);
        $order=$or->info();
        $mid = (string)$order['mainOrder']->UUaid;
        $orderId=(string)$order['mainOrder']->UUordernum;
        $sel="SELECT id FROM `pft_alipay_rec` WHERE out_trade_no=$orderId LIMIT 1";
        $GLOBALS['le']->query($sel);
        $GLOBALS['le']->fetch_assoc();
        if(!$GLOBALS['le']->f('id')){
            $subject=(string)$order['mainOrder']->UUltitle.(string)$order['mainOrder']->UUttitle;
            $total_fee=((string)$order['mainOrder']->UUtprice * (string)$order['mainOrder']->UUtnum)/100;
            // 加上非套票的子票金额
            if(count($order['childOrder']) && $order['mainOrder']->UUp_type!='F'){
                foreach($order['childOrder'] as $key=>$child){
                    $total_fee+=((string)$child->UUtprice * (string)$child->UUtnum)/100;
                }
            }
            $show_url = $script_uri.'/scenicDetail.html?lid='.(string)$order['mainOrder']->UUlid;
            $ins = "INSERT INTO `pft_alipay_rec` (out_trade_no,seller_email,subject,total_fee,description,show_url,royalty_parameters,status,dtime) VALUES ($orderId,'3099889658@qq.com','$subject','$total_fee','会员购买$subject','$show_url','',0,now())";
            $GLOBALS['le']->query($ins);
        }
        $totalMenoey+=(string)$order['totalPrice'];
    }

    $or->alipay_cst($ordernum,'订单支付:'.$ordernum,$totalMenoey/100,$mid);
    exit;
}
// print_r($_SESSION);
// exit;
$or=new OrderRecord_c($ordernum,$s);

$order=$or->info();

if(time()-strtotime((string)$order['mainOrder']->UUordertime)>3600){
    echo '<script>alert("订单已过1小时的支付期限");history.go(-1)</script>';
    echo '<script>window.close();</script>';
    exit;
}
$orderId=(string)$order['mainOrder']->UUordernum;
$sel="SELECT id FROM `pft_alipay_rec` WHERE out_trade_no=$orderId LIMIT 1";
$GLOBALS['le']->query($sel);
$GLOBALS['le']->fetch_assoc();
if(!$GLOBALS['le']->f('id')){
    $subject=(string)$order['mainOrder']->UUltitle.(string)$order['mainOrder']->UUttitle;
    $total_fee=((string)$order['mainOrder']->UUtprice * (string)$order['mainOrder']->UUtnum)/100;
    // 加上非套票的子票金额
    if(count($order['childOrder']) && $order['mainOrder']->UUp_type!='F'){
        foreach($order['childOrder'] as $key=>$child){
            $total_fee+=((string)$child->UUtprice * (string)$child->UUtnum)/100;
        }
	}
    $show_url =$script_uri.'/scenicDetail.html?lid='.(string)$order['mainOrder']->UUlid;
    $ins = "INSERT INTO `pft_alipay_rec` (out_trade_no,seller_email,subject,total_fee,description,show_url,royalty_parameters,status,dtime) VALUES ($orderId,'3099889658@qq.com','$subject','$total_fee','会员购买$subject','$show_url','',0,now())";
    if($GLOBALS['le']->query($ins)){
        $or->alipay_c();
    }
}else{
    $or->alipay_c();
}
?>